import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class test2 {
    public static void main(String[] args) throws IOException {
        System.out.println("写入文件:");
        FileOutputStream fileOutputStream = new FileOutputStream("StudentsDatas.txt");
        boolean flag = false;
        Scanner scanner = new Scanner(System.in);
        for (int i = 1; i <= 5; i++) {
            System.out.println("请输入第" + i + "个学生的成绩：");
            int in = scanner.nextInt();
            fileOutputStream.write(in);
            flag = true;
        }
        fileOutputStream.close();
        if(flag) {
            System.out.println("写入成功！");
        }
        System.out.println("读取文件:");
        FileInputStream fileInputStream = new FileInputStream("StudentsDatas.txt");
        int[] arr = new int [5];
        int num = 0;
        for(int i = 0; i < 5;i++) {
            arr[i] = fileInputStream.read();
            num += arr[i];
        }
        fileInputStream.close();
        int sum = num / 5;
        System.out.println("这五个学生的平均数为：" + sum);
        System.out.print("从大到小排序：");
        Arrays.sort(arr);
        for(int i = arr.length - 1;i >= 0;i--) {
            System.out.print(arr[i]+" ");
        }
    }
}
